package com.cmdandroid.icebutton;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.Contacts;
import android.provider.Contacts.People;

@SuppressWarnings({ "deprecation"})
class OldContactsAdapterBridge extends ContactsAdapterBridge {
	
	String name, number, id, numberType;
	
	List<String> info = new ArrayList<String>();
	
	List<String> getInfo(Activity a, Intent data) {
		
	Uri contactData = data.getData();
	
	Cursor c = a.managedQuery (contactData, null, null, null, null);
	
	int nameColumn = c.getColumnIndex(People.NAME);
	
	//Move cursor to first position and grab name

	c.moveToFirst();
		if (c.moveToFirst()){
			name = c.getString(nameColumn);
			//clear info first
			info.clear();
			info.add(name);
		}
		
		//Grab id for WHERE condition
		id = contactData.getLastPathSegment();
		//WHERE condition arguments for ?
		String[] args = new String[]{id};
		//Create cursor to look for Phones that belong to
		//selected contacts ID
		Cursor pCur = a.managedQuery(Contacts.Phones.CONTENT_URI,
			null,
			Contacts.Phones.PERSON_ID + " = ?",
			args, null);
		//Go through each phone number and grab its type as well
		while (pCur.moveToNext()) {
			number = pCur.getString(
					pCur.getColumnIndex(Contacts.Phones.NUMBER));
			info.add(number);
			//TODO:
			//For now, type is not passed back
			//Can include this once type is implemented in
			//NewContactsAdapterBridge as well
			numberType = pCur.getString(
					pCur.getColumnIndex(Contacts.Phones.TYPE));
		}
		
	return info;
	}
}


